import type { PageDto, PageReqDto, PagesDto } from '@/api/types'
import request from '@/utils/request'
import type {PeriodInsurClaimDto,ReportCaseResultDto, LongInsuranceCaseListDto, LongInsuranceCaseDto, InsuranceCountDto, InsurancePlanDto,InsuraceeCompanyListDto, InsurancePlanReqDto, OperateRecordDto, PeriodDataDto, PlanReqDto, OperateRecordDetailDto, InsuranceCheckDto, InsuraceStaffDto, InsuraceStaffReqDto,InsuraceSaleDto, DayInsuranceCaseDto, DailyInsurClaimOneDto, DailyInsurClaimTwoDto, PeriodInsuranceMaterialsDto, InsuranceMaterialsFileDto, PeriodUtdangerListStaffDto, UploadPeriodInsuranceDto, PeriodInsuranceCaseReqDto, OneKeyDetailDto, OnekeyDto } from './types'


// 长期保可欠费额度更新
export function updatePeriodOverdraftAmount(data: {
    companyId: number
    overdraftAmount: number
}): Promise<string> {
    return request.put('/crm-prod/wesure/account-balance/update-period-overdraft-amount', data)
}

// 长期保超龄减保
export function periodOverageReduce(data: {
    companyId: number
    companyPlanId: number
    ids: number[]
    insurEndDay: string
}): Promise<string> {
    return request.post('/crm-prod/rest/period-insur/staff-record/terminal-ensure-overage', data)
}

// 长期保设置超龄人数
export function updateAllowOverageEnsure(data: {
    companyId: number
    allowOverageEnsure: number | null
}): Promise<string> {
    return request.post('/crm-prod/insur-com-company/insur-com-company/updateAllowOverageEnsure', data)
}

/**
 * 获取保险计划列表
 * 
 * 该函数通过发送POST请求来获取保险计划的分页列表它结合了分页请求DTO和保险计划请求DTO的参数，
 * 并返回一个包含保险计划信息的PagesDto对象的Promise
 * 
 * @param data 一个对象，包含分页请求和保险计划请求的数据
 * @returns 返回一个Promise，解析为包含保险计划Dto的PagesDto对象
 */
export function getInsurancePlanList(params: PageReqDto & InsurancePlanReqDto): Promise<PageDto<InsurancePlanDto>> {
    return request.get('/crm-prod/insur/InsurComCompanyPlans/list', {
        params
    })
}

// 长期保查看保险信息(方案,加减保次数,减保人数)
export function getPeriodInfo(params: {
    companyId: number
}): Promise<PeriodDataDto> {
    return request.get('/crm-prod/period-insur/client/query-period-info', {
        params
    })
}

// 获取公司保险方案
export function getInsurancePlans(id: number): Promise<InsurancePlanDto> {
    return request.get(`/crm-prod/insur/InsurComCompanyPlans/${id}`)
}

// 长期保 修改保险方案
export function updateCompanyPlans(data: PlanReqDto): Promise<string> {
    return request.put('/crm-prod/insur/InsurComCompanyPlans', data)
}

// 长期保 删除方案
export function deletePlans(id: number): Promise<string> {
    return request.delete(`/crm-prod/insur/InsurComCompanyPlans/${id}`)
}

// 长期保 导出方案
export function exportPlans(params: {
    companyId: number
    isDelete?: number
}): Promise<string> {
    return request.get('/crm-prod/insur/InsurComCompanyPlans/export', {
        params
    })
}

// 加减保记录
export function getOperateRecordList(params: PageReqDto & {
    companyId: number
    beginInsureDay?: string
    endInsureDay?: string
}): Promise<PageDto<OperateRecordDto>> {
    return request.get('/crm-prod/period-insur/operate-record/list', {
        params
    })
}

// 加减保记录详情
export function getOperateRecordDetailList(params: PageReqDto & {
    operateRecordId: number
}): Promise<PageDto<OperateRecordDetailDto>> {
    return request.get('/crm-prod/period-insur/operate-record/detail', {
        params
    })
}

// 投保审核列表
export function getInsuranceCheckList(params: PageReqDto & {
    status?: number
    companyId: number
    serveCompanyName?: string
}): Promise<PageDto<InsuranceCheckDto>> {
    return request.get('/crm-prod/period-insur/serve-company/query-svc-occ', {
        params
    })
}

// 获取投保人员列表
export function getInsuranceStaffList(params: PageReqDto & Partial<InsuraceStaffReqDto>): Promise<PageDto<InsuraceStaffDto>> {
    return request.get('/crm-prod/period-insur/staff-record/list', {
        params
    })
}

// 导出投保人员列表
export function exportStaffRecord(params: Partial<InsuraceStaffReqDto>): Promise<string> {
    return request.get('/crm-prod/period-insur/staff-record/export', {
        params
    })
}

// 导出在保证明pdf
export function exporProvedPdf(params: Partial<InsuraceStaffReqDto & {
    queryStartDate: string
    queryEndDate: string
}>): Promise<string> {
    return request.get('/crm-prod/period-insur/staff-record/in-warranty-proved-export-pdf', {
        params
    })
}
// 导出在保证明excel
export function exporProved(params: Partial<InsuraceStaffReqDto & {
    queryStartDate: string
    queryEndDate: string
}>): Promise<string> {
    return request.get('/crm-prod/period-insur/staff-record/in-warranty-proved-export', {
        params
    })
}

// 导出在保证明人员
export function exporStaff(params: Partial<InsuraceStaffReqDto & {
    queryStartDate: string
    queryEndDate: string
}>): Promise<string> {
    return request.get('/crm-prod/period-insur/staff-record/in-warranty-staff-export', {
        params
    })
}


// InsuraceStaffDto[]
// 获取商务人员列表 /crm/sales/query-sales-list 
export function getSaleList(params: {
	isSelectSale: number,
	salesName:string
}): Promise<InsuraceSaleDto[]> {
    return request.get('/crm-prod/crm/sales/query-sales-list', {
        params
    })
}

// 获取保司列表 
export function getInsuranceCompanyList(): Promise<InsuraceeCompanyListDto[]> {
    return request.get('/crm-prod/insur/insurComInsuranceCompany/query-period-insurance-company')
}

// 长期保案件统计 
export function getLongInsuranceCount(): Promise<InsuranceCountDto> {
    return request.get('/crm-prod/period-insur/report-case/summarizing-insur-report-case-data')
}

// 获取长期保案件列表 /period-insur/report-case/list /crm-prod/period-insur/staff-record/list
export function getLongInsuranceCaseList(params: PageReqDto & LongInsuranceCaseDto): Promise<LongInsuranceCaseListDto<ReportCaseResultDto>[]> {
    return request.get('/crm-prod/period-insur/report-case/list', {
        params
    })
}


// 获取日日保案件统计数据
export function getDayInsuranceCount(): Promise<InsuranceCountDto> {
    return request.get('/crm-prod/wesure/wesure-report-case/summarizing-wesure-report-case-data')
}

// 获取日日保案件列表 
export function getDayInsuranceCaseList(params: PageReqDto & DayInsuranceCaseDto): Promise<LongInsuranceCaseListDto<ReportCaseResultDto>[]> {
    return request.get('/crm-prod/wesure/wesure-report-case/report-case-list', {
        params
    })
}


// 删除长期保案件经过 
export function dellongInsuranceProcess(id:number): Promise<void> {
    return request.delete('/crm-prod/period-insur/report-case-result/delete/' + id)
}

// 删除日日保案件经过  
export function delDayInsuranceProcess(id:number): Promise<void> {
    return request.delete('/crm-prod/wesure/wesure-report-case/wesure-report-case-result/delete/' + id)
}

// 允许添加补充材料的保司 
export function getMaterialInsureCompany(): Promise<string[]> {
    return request.get('/crm-prod/period-insur/report-case/materials-insur-company')
}


// 修改长期保理赔状态
export function setPeriodInsurClaim(params: PeriodInsurClaimDto): Promise<void> {
    return request.put('/crm-prod/period-insur/report-case', params)
}
// 修改日日b保理赔状态步骤1
export function setDailyInsurClaimOne(params: DailyInsurClaimOneDto): Promise<void> {
    return request.put('/crm-prod/wesure/wesure-report-case', params)
}
// 修改日日b保理赔状态步骤2
export function setDailyInsurClaimTwo(params: DailyInsurClaimTwoDto): Promise<void> {
    return request.put('/crm-prod/wesure/wesure-report-case/add-report-result', params)
}


// 获取长期保理赔材料列表 
export function getPeriodInsuranceMaterials(params: {
	reportCaseId: number
	insureCompany: string
}): Promise<PeriodInsuranceMaterialsDto<InsuranceMaterialsFileDto>[]> {
    return request.get('/crm-prod/period-insur/report-case/materials', {
        params
    })
}


// 上传长期保理赔材料  
export function addPeriodInsuranceMaterials(params: {
	categoryType: number
	companyId: number
	file: string
	reportCaseId:number
}): Promise<InsuranceMaterialsFileDto> {
    return request.put('/crm-prod/period-insur/report-case/materials-add', params)
}

// 删除长期保理赔材料   removeMaterialsLong
export function removePeriodInsuranceMaterials(param: number): Promise<void> {
    return request.post(`/crm-prod/period-insur/report-case/materials-del/?fileId=${param}`, )
}

// 导出长期保理赔材料  exportImagesLong
export function exportPeriodInsuranceMaterials(params: {
	reportCaseId: number
	insureCompany: string
}): Promise<string> {
    return request.get('/crm-prod/period-insur/report-case/download-report-case-images', {
        params,
        responseType: 'arraybuffer'
    })
}

// 获取日日保理赔材料列表
export function getDailyInsuranceMaterials(params: {
	reportCaseId: number
	insureCompany: string
}): Promise<PeriodInsuranceMaterialsDto<InsuranceMaterialsFileDto>[]> {
    return request.get('/crm-prod/wesure/wesure-report-case/materials', {
        params
    })
}

// 上传日日保理赔材料  
export function addDailyInsuranceMaterials(params: {
	categoryType: number
	companyId: number
	file: string
	reportCaseId:number
}): Promise<InsuranceMaterialsFileDto> {
    return request.put('/crm-prod/wesure/wesure-report-case/materials-add', params)
}

// 删除日日保理赔材料   
export function removeDailyInsuranceMaterials(param: number): Promise<void> {
    return request.post(`/crm-prod/wesure/wesure-report-case/materials-del/?fileId=${param}`, )
}


// 导出日日保理赔材料  
export function exportDailyInsuranceMaterials(params: {
	reportCaseId: number
	insureCompany: string
}): Promise<string> {
    return request.get('/crm-prod/wesure/wesure-report-case/download-report-case-images', {
        params,
        responseType: 'arraybuffer'
    })
}

// 导出长期保案件列表 
export function exportPeriodInsuranceCaseList(params: LongInsuranceCaseDto): Promise<string> {
    return request.get('/crm-prod/period-insur/report-case/export', {
        params
    })
}

// 导出日保案件列表
export function exportDailyInsuranceCaseList(params: DayInsuranceCaseDto): Promise<string> {
    return request.get('/crm-prod/wesure/wesure-report-case/export', {
        params
    })
}

// 长期保出险人  
export function getPeriodUtdangerListStaff(params: {
	companyId: number
	searchUserInfo: string
	isAdmin: number
}): Promise<PageDto<PeriodUtdangerListStaffDto>> {
    return request.get('/crm-prod/rest/period-insur/staff-record/out-danger-list-staff', {
        params
    })
}

// 长期保创建理赔上传附件方法
export function uploadPeriodInsuranceVideo(data: FormData): Promise<UploadPeriodInsuranceDto> {
    return request.post('/crm-prod/rest/period-insur/serve-company/upload', data )
}

// 长期保创建理赔
export function addPeriodInsuranceCase(data: PeriodInsuranceCaseReqDto<UploadPeriodInsuranceDto>): Promise<void> {
    return request.post('/crm-prod/rest/period-insur/insur-period-report-case/report-case', data )
}

/**
 * 获取一键续保列表
 * @param params 
 * @returns 
 */
export function getOnekeyList(params: PageReqDto & {
	companyName?: string
	deptId?: number
	saleId?: number
}): Promise<PageDto<OperateRecordDto>> {
    return request.get('/crm-prod/period-insur/onekey/list', {
        params
    })
}

/**
 * 一键续保详情
 * @param params 
 * @returns 
 */
export function getOnekeyDetail(params: {
	companyId?: number
	onekeyEnsureType?: number
}): Promise<OneKeyDetailDto> {
    return request.get('/crm-prod/period-insur/onekey/detail', {
        params
    })
}

/**
 * 一键续保
 * @param data 
 * @returns 
 */
export function handleOnekey(data: {
	companyId?: number
	onekeyEnsureType?: number
}): Promise<OnekeyDto> {
    return request.post('/crm-prod/period-insur/onekey/ensure', data)
}

/**
 * 保单可撤销列表
 * @param params 
 * @returns 
 */
export function getRevokeInsuranceList(params: PageReqDto & {
	companyName?: string
}): Promise<PageDto<OperateRecordDto>> {
    return request.get('/crm-prod/period-insur/operate-record/query-revoke-ensure-list', {
        params
    })
}

/**
 * 询长期保险保险操作记录投保人员列表
 * @param params 
 * @returns 
 */
export function getOperateRecordPeopleList(params: PageReqDto & {
	id: number
    companyPlanId: number
}): Promise<PagesDto<OperateRecordDto>> {
    return request.get('/crm-prod/period-insur/operate-record/detail-recordId', {
        params
    })
}

/**
 * 获取表单撤销记录
 * @param params 
 * @returns 
 */
export function getAlreadyRevokedList(params: PageReqDto & {
    companyName?: string
}): Promise<PageDto<OperateRecordDto>> {
    return request.get('/crm-prod/period-insur/operate-record/query-already-revoke-ensureList', {
        params
    })
}
